From 886c6ddf910e577377cbf64a83d9a6b7a35c44da Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Tue, 6 Jul 2004 14:04:02 +0000 Subject: [PATCH] Added turns_only and turns_important to saroute --- README | 13 +++++++++++++ defs.h | 11 +++++++++++ saroute.c | 24 ++++++++++++++++++++++-- smplrout.c | 18 +++++++++++------- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/README b/README index 4c3738e79..a47ff7050 100644 --- a/README +++ b/README @@ -470,7 +470,20 @@ THE FORMATS This is a catch-all used by many Delorme mapping products and reads the anr, rte, and rtd formats as either tracks or routes. + + The 'turns_only' option causes GPSBabel to read only the waypoints + associated with named turns. This should create a list of waypoints + that correspond to the itinerary from Street Atlas. + The 'turns_important' option only makes sense in conjunction with + the 'simplify' filter. It ensures that the route simplification + process will remove the points corresponding to turns only after + it has removed all other route points. + + Both options only apply to route files from newer versions of + DeLorme software; older versions didn't store the turn information + with the route. + saplus This format is for Street Atlas USA 2004 Plus. diff --git a/defs.h b/defs.h index b6d36c20f..a6fbfe7f6 100644 --- a/defs.h +++ b/defs.h @@ -193,6 +193,17 @@ typedef struct { const char *icon_descr; time_t creation_time; /* standardized in UTC/GMT */ int centiseconds; /* Optional hundredths of a second. */ + + /* + * route priority is for use by the simplify filter. If we have + * some reason to believe that the route point is more important, + * we can give it a higher (numerically; 0 is the lowest) priority. + * This causes it to be removed last. + * This is currently used by the saroute input filter to give named + * waypoints (representing turns) a higher priority. + */ + int route_priority; + geocache_data gc_data; xml_tag *gpx_extras; void *extra_data; /* Extra data added by, say, a filter. */ diff --git a/saroute.c b/saroute.c index f79a50795..04d66aeb7 100644 --- a/saroute.c +++ b/saroute.c @@ -28,6 +28,18 @@ FILE *infile; +char *turns_important = NULL; +char *turns_only = NULL; + +static +arglist_t saroute_args[] = { + {"turns_important", &turns_important, + "Keep turns if simplify filter is used", ARGTYPE_BOOL }, + {"turns_only", &turns_only, "Only read turns; skip all other points", + ARGTYPE_BOOL }, + {0, 0, 0, 0 } +}; + unsigned short ReadShort(FILE * f) { @@ -221,12 +233,20 @@ my_read(void) wpt_tmp->latitude = lat; wpt_tmp->longitude = -lon; wpt_tmp->shortname = (char *) xmalloc(7); + if ( turns_important && stringlen ) + wpt_tmp->route_priority=1; sprintf( wpt_tmp->shortname, "\\%5.5x", serial++ ); - route_add_wpt(track_head, wpt_tmp); + if ( !turns_only || stringlen ) + route_add_wpt(track_head, wpt_tmp); latlon++; coordcount--; + stringlen = 0; + /* the stop point is a "turn" */ + if ( coordcount == 1 && count == 0 ) { + stringlen = 1; + } } xfree(record); } @@ -252,5 +272,5 @@ ff_vecs_t saroute_vecs = { NULL, my_read, NULL, - NULL + saroute_args }; diff --git a/smplrout.c b/smplrout.c index 5360d103d..f20592149 100644 --- a/smplrout.c +++ b/smplrout.c @@ -29,7 +29,7 @@ static char *countopt = NULL; static arglist_t routesimple_args[] = { - {"count", &countopt, "Maximum number of points in final route", + {"count", &countopt, "Maximum number of points in route", ARGTYPE_INT | ARGTYPE_REQUIRED}, {0, 0, 0, 0} }; @@ -108,9 +108,14 @@ compute_xte( struct xte *xte_rec ) { int compare_xte( const void *a, const void *b ) { - double foo = (((struct xte *)a)->distance - ((struct xte *)b)->distance ); - if ( foo < 0 ) return 1; - if ( foo > 0 ) return -1; + double distdiff = ((struct xte *)a)->distance - + ((struct xte *)b)->distance; + int priodiff = ((struct xte *)a)->intermed->wpt->route_priority - + ((struct xte *)b)->intermed->wpt->route_priority; + if ( priodiff < 0 ) return 1; + if ( priodiff > 0 ) return -1; + if ( distdiff < 0 ) return 1; + if ( distdiff > 0 ) return -1; return 0; } @@ -134,8 +139,7 @@ void shuffle_xte( struct xte *xte_rec ) { struct xte tmp_xte; - while ( xte_rec > xte_recs && - xte_rec->distance > xte_rec[-1].distance ) { + while ( xte_rec > xte_recs && compare_xte(xte_rec, xte_rec-1) < 0 ) { tmp_xte.distance = xte_rec->distance; tmp_xte.ordinal = xte_rec->ordinal; tmp_xte.intermed = xte_rec->intermed; @@ -150,7 +154,7 @@ shuffle_xte( struct xte *xte_rec ) xte_rec->intermed->xte_rec = xte_rec; } while ( xte_rec - xte_recs < xte_count-2 && - xte_rec->distance < xte_rec[1].distance ) { + compare_xte( xte_rec, xte_rec+1) > 0 ) { tmp_xte.distance = xte_rec->distance; tmp_xte.ordinal = xte_rec->ordinal; tmp_xte.intermed = xte_rec->intermed; -- 2.30.2